﻿using TradePublish.Common;
using log4net;
using TradePublish.Service;
using System;
using System.Data;
using System.Reflection;
using System.Threading;
using TradePublish.Common;
using TradePublish.Service;

public class IPListDao
{
    private ILog log = null;

    public IPListDao()
    {
        this.log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
    }

    public string getIp()
    {
        if ((Global.serverNameInlan != null) && !Global.serverNameInlan.Equals(""))
        {
            return Global.serverNameInlan;
        }
        string commandText = " select Ip  from IpList  where IpID='cgxt-fc244e3c4f'";
        DataSet set = new DataSet();
        while (true)
        {
            DatabaseHelper dbh = new DatabaseHelper(Global.IPDBLinkStrSQL,Providers.SqlServer);
            try
            {
                set = dbh.ExecuteDataSet(  commandText );
                if ((((set != null) && (set.Tables.Count > 0)) && (set.Tables[0].Rows != null)) && (set.Tables[0].Rows.Count > 0))
                {
                    return set.Tables[0].Rows[0][0].ToString();
                }
                this.log.Info("获取远程IP为null.SQL=" + commandText);
                Thread.Sleep(0x7d0);
            }
            catch (Exception exception)
            {
                this.log.Error("获取远程IP出现异常.", exception);
                Thread.Sleep(0x7d0);
            }
            finally
            {
                dbh.Dispose();
            }
        }
    }
}

